import { Injectable } from '@nestjs/common';
import { CreateZoneDto } from './dto/create-zone.dto';
import { UpdateZoneDto } from './dto/update-zone.dto';
import { PrismaService } from 'src/prisma/prisma.service';

@Injectable()
export class ZoneService {
  constructor(private prisma: PrismaService) {}
  async create(createZoneDto: CreateZoneDto) {
    return await this.prisma.zone.create({
      data: {
        name: createZoneDto.name,
        projId: +createZoneDto.projId,
      },
    });
  }

  async findAll(args: Record<string, any>) {
    const { projId } = args;
    const data = await this.prisma.zone.findMany({
      where: { projId: +projId },
      // include: { CalculateZone: true },
    });
    return data;
  }

  async findOne(id: number) {
    return await this.prisma.zone.findUnique({
      where: { id },
      include: {
        proj: {
          select: { shortName: true },
        },
        CalculateZone: true,
      },
    });
  }

  async update(id: number, updateZoneDto: UpdateZoneDto) {
    return this.prisma.zone.update({ where: { id }, data: updateZoneDto });
  }

  async remove(id: number) {
    return await this.prisma.zone.delete({ where: { id } });
  }
}
